package com.example.campus;

import java.util.ArrayList;

import com.campus.map.Map;
import com.news.m.InfoAnnoucement;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TableLayout;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class MainActivity extends Activity implements OnItemClickListener,
		OnClickListener {
	Indicator indicator;
	ListView nevigation;
	TextView info1;
	TextView info2;
	TextView info3;
	TextView info4;
	ViewPager vp;
	ArrayList<ItemInfo> infolist;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		info1 = (TextView) findViewById(R.id.tab_one);
		info1.setOnClickListener(this);
		info2 = (TextView) findViewById(R.id.tab_two);
		info2.setOnClickListener(this);
		info3 = (TextView) findViewById(R.id.tab_three);
		info3.setOnClickListener(this);
		info4 = (TextView) findViewById(R.id.tab_four);
		info4.setOnClickListener(this);

		nevigation = (ListView) findViewById(R.id.navigation_drawer_list);
		nevigation.setSelection(1);
		infolist = createinfolist();
		nevigation.setAdapter(new NavigationAdapter(this, infolist));

		indicator = (Indicator) findViewById(R.id.indicator);
		vp = (ViewPager) findViewById(R.id.viewpager);
		vp.setAdapter(new ViewPagerAdapter(new String[] { "1", "2", "3", "4" },
				this));
		nevigation.setOnItemClickListener(this);

		vp.setOnPageChangeListener(new OnPageChangeListener() {

			@Override
			public void onPageSelected(int arg0) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub
				indicator.scroll(arg0, arg1);
			}

			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub

			}
		});

	}

	ArrayList<ItemInfo> createinfolist() {
		ArrayList<ItemInfo> list = new ArrayList<ItemInfo>();
		ItemInfo item = new ItemInfo();
		item.name = "资讯";
		item.listener = new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

			}
		};
		item.iconid = R.drawable.icon_nav_course;
		list.add(item);
		ItemInfo item2 = new ItemInfo();
		item2.name = "查询";
		item2.listener = new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent i = new Intent(MainActivity.this, SearchActivity.class);
				startActivity(i);
			}
		};
		item2.iconid = R.drawable.icon_nav_inquire;
		list.add(item2);
		ItemInfo item3 = new ItemInfo();
		item3.name = "地图";
		
		item3.listener = new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent i = new Intent(MainActivity.this, Map.class);
				startActivity(i);
			}
		};
		item3.iconid = R.drawable.map;
		list.add(item3);
		return list;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v.getId() == R.id.tab_one)
			vp.setCurrentItem(0);
		else if (v.getId() == R.id.tab_two)
			vp.setCurrentItem(1);
		else if (v.getId() == R.id.tab_three)
			vp.setCurrentItem(2);

		else if (v.getId() == R.id.tab_four)
			vp.setCurrentItem(3);

	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		// TODO Auto-generated method stub
		infolist.get(position).listener.onClick(view);
	}
}
